package com.woniuxy.controller;

import com.woniuxy.entity.dto.system.RoleDTO;
import com.woniuxy.entity.po.system.Dept;
import com.woniuxy.entity.po.system.Role;
import com.woniuxy.service.DeptService;
import com.woniuxy.service.RoleService;
import com.woniuxy.util.CodeUtil;
import com.woniuxy.util.PageParam;
import com.woniuxy.util.ResponseData;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/role")
@AllArgsConstructor
public class RoleController {
    private RoleService roleService;
    private CodeUtil codeUtil;
    /**
     * 查询所有的dept数据，带到页面回显（分页回显）
     * @return
     */
    @PostMapping("/queryAll")
    public ResponseData<?> queryAll(@RequestBody PageParam<RoleDTO> pageParam){
        return roleService.queryAll(pageParam);
    }

    @GetMapping("/deleteRole/{id}")
    public ResponseData<?> deleteRole(@PathVariable("id")Long id){
        roleService.deleteRole(id);
        return ResponseData.ok();
    }
    @PostMapping("/batchDeleteRole")
    public ResponseData<?> BatchDeleteRole(@RequestBody List<Long> ids){
        roleService.batchDeleteRole(ids);
        return ResponseData.ok();
    }
    @PostMapping("/addRole")
    public ResponseData<?> addRole(@RequestBody Role role){
        roleService.addRole(role);
        return ResponseData.ok();
    }
    @PostMapping("/updateRole")
    public ResponseData<?> updateRole(@RequestBody RoleDTO roleDTO){
        roleService.updateRole(roleDTO);
        return ResponseData.ok();
    }
    @GetMapping("/queryIdInfo/{id}")
    public ResponseData<?> queryIdInfo(@PathVariable("id") Long id){

        return ResponseData.ok(roleService.queryIdInfo(id));
    }
    @GetMapping("/queryRole")
    public ResponseData<?> queryRole(){
        return ResponseData.ok(roleService.queryRole());
    }
    @GetMapping("/getCode")
    public ResponseData<?> getCode() {
        return ResponseData.ok(codeUtil.generateRegularCode("ROLE"));
    }
}
